package com.xhwl.logistics.service.business;

import com.xhwl.common.exception.BusinessException;
import com.xhwl.logistics.bo.VehicleFindCarBO;
import com.xhwl.logistics.bo.VehicleParkingLotSecondBO;
import com.xhwl.logistics.bo.cent.VehicleIntegratedConfigBO;
import com.xhwl.logistics.bo.input.QueryVehicleFindCarBO;
import com.xhwl.logistics.component.LookupVehicleParkingLotHandler;
import com.xhwl.logistics.service.cent.QueryDeviceService;
import com.xhwl.logistics.service.impl.VehicleParkingLotServiceImpl;
import com.xhwl.logistics.strategy.IVehicleParkingLotFindCarHandler;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

//@Service
public class VehicleFindCarBusinessService {

    @Autowired
    private LookupVehicleParkingLotHandler lookupVehicleParkingLotHandler;

    @Autowired
    private QueryDeviceService queryDeviceService;

    @Autowired
    private VehicleParkingLotServiceImpl vehicleParkingLotService;

    public VehicleFindCarBO findCar(QueryVehicleFindCarBO queryVehicleFindCarBO) {
        List<VehicleParkingLotSecondBO> vehicleParkingLotSecondBOList = vehicleParkingLotService.queryParkingLots(queryVehicleFindCarBO.getProjectId(), queryVehicleFindCarBO.getParkingLotName());
        if (vehicleParkingLotSecondBOList.size() > 1) {
            throw new BusinessException("通过输入的项目id和车场名称，存在多个车场");
        }
        if (vehicleParkingLotSecondBOList.size() < 1) {
            throw new BusinessException("通过输入的项目id和车场名称，不存在车场");
        }

        VehicleIntegratedConfigBO vehicleIntegratedConfigBO = queryDeviceService.queryIntegratedConfigFromProjectId(queryVehicleFindCarBO.getProjectId());

        IVehicleParkingLotFindCarHandler vehicleParkingLotFindCarHandler = lookupVehicleParkingLotHandler.lookupForFindCarHandler(vehicleIntegratedConfigBO.getVehicleSystemInfoBO().getProductId());
        return vehicleParkingLotFindCarHandler.findCar(vehicleIntegratedConfigBO, queryVehicleFindCarBO);
    }

}
